package com.facotry.util;

import com.facotry.ex.NoLoginException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * --- 代码敲烂 月薪过万 ---
 *
 * @author 崔瑜航
 * @date 2024/7/30
 * @desc  全局异常类
 */
@RestControllerAdvice
public class GlobalHandleException {
    @ExceptionHandler(NoLoginException.class)
    public R handleException(Exception ex){
        System.out.println("出错啦!" + ex.getMessage());
        NoLoginException noLoginException = (NoLoginException) ex;
        // 返回状态码和错误信息
        return R.fail(noLoginException.getCode(),noLoginException.getMessage() );
    }
}
